class CriteriasController < ApplicationController
  layout 'main'
  
  before_filter :admin_required
  
  # GET /criterias
  # GET /criterias.xml
  def index
    @criterias = Criteria.find(:all)

    respond_to do |format|
      format.html # index.html.erb
      format.xml  { render :xml => @criterias }
    end
  end

  # GET /criterias/1
  # GET /criterias/1.xml
  def show
    @criteria = Criteria.find(params[:id])

    respond_to do |format|
      format.html # show.html.erb
      format.xml  { render :xml => @criteria }
    end
  end

  # GET /criterias/new
  # GET /criterias/new.xml
  def new
    @criteria = Criteria.new

    respond_to do |format|
      format.html # new.html.erb
      format.xml  { render :xml => @criteria }
    end
  end

  # GET /criterias/1/edit
  def edit
    @criteria = Criteria.find(params[:id])
  end

  # POST /criterias
  # POST /criterias.xml
  def create
    @criteria = Criteria.new(params[:criteria])

    respond_to do |format|
      if @criteria.save
        flash[:notice] = 'Criteria was successfully created.'
        format.html { redirect_to(@criteria) }
        format.xml  { render :xml => @criteria, :status => :created, :location => @criteria }
      else
        format.html { render :action => "new" }
        format.xml  { render :xml => @criteria.errors, :status => :unprocessable_entity }
      end
    end
  end

  # PUT /criterias/1
  # PUT /criterias/1.xml
  def update
    @criteria = Criteria.find(params[:id])

    respond_to do |format|
      if @criteria.update_attributes(params[:criteria])
        flash[:notice] = 'Criteria was successfully updated.'
        format.html { redirect_to(@criteria) }
        format.xml  { head :ok }
      else
        format.html { render :action => "edit" }
        format.xml  { render :xml => @criteria.errors, :status => :unprocessable_entity }
      end
    end
  end

  # DELETE /criterias/1
  # DELETE /criterias/1.xml
  def destroy
    @criteria = Criteria.find(params[:id])
    @criteria.destroy

    respond_to do |format|
      format.html { redirect_to(criterias_url) }
      format.xml  { head :ok }
    end
  end
end
